AddStategraphState('wilson',
---@diagnostic disable-next-line: undefined-global
State{
    name = "kukude_scalpel",
    tags = {'doing','busy'},

    ---@param inst ent
    onenter = function(inst)
        inst.components.locomotor:Stop()
        inst.AnimState:PlayAnimation("wrap_pre")
        inst.AnimState:PushAnimation("wrap_loop", true)
    end,

    timeline =
    {
        TimeEvent(7 * FRAMES, function(inst)
            inst.sg:RemoveStateTag("busy")
        end),
        TimeEvent(9 * FRAMES, function(inst)
            inst:PerformBufferedAction()
        end),
    },

    events =
    {
        EventHandler("animqueueover", function(inst)
            if inst.AnimState:AnimDone() then
                inst.sg:GoToState("idle")
            end
        end),
    },

    onexit = function(inst)
        if not inst.sg.statemem.bundling then
            inst.SoundEmitter:KillSound("make")
        end
        ---@type ent
        local fleshsack = inst.components.inventory and inst.components.inventory:GetEquippedItem(EQUIPSLOTS.KKD_FLESH)
        if fleshsack ~= nil and fleshsack.components.container ~= nil then
            fleshsack.components.container:Close(inst)
        end
    end,
})


AddStategraphState('wilson_client',
---@diagnostic disable-next-line: undefined-global
State{
    name = "kukude_scalpel",
    tags = { "doing", "busy" },
    -- server_states = { "bundle" },

    onenter = function(inst)
        inst.components.locomotor:Stop()
        inst.SoundEmitter:PlaySound("dontstarve/wilson/make_trap", "make_preview")
        inst.AnimState:PlayAnimation("wrap_pre")
        inst.AnimState:PushAnimation("wrap_loop", true)

        inst:PerformPreviewBufferedAction()
        -- inst.sg:SetTimeout(TIMEOUT)
    end,

    timeline =
    {
        TimeEvent(7 * FRAMES, function(inst)
            inst.sg:RemoveStateTag("busy")
        end),
    },

    ontimeout = function(inst)
        inst:ClearBufferedAction()
        inst.AnimState:PlayAnimation("wrap_pst")
        inst.sg:GoToState("idle", true)
    end,

    onexit = function(inst)
        inst.SoundEmitter:KillSound("make_preview")
    end,
})